package com.yuw.control.userinfoajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.yuw.bean.UserInfoBean;
import com.yuw.model.UserInfoModel;
import com.yuw.utils.EasyFactory;
import com.yuw.utils.MyUtils;

@WebServlet("/UserInfoAjaxQueryControl")
public class UserInfoAjaxQueryControl extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 使用form表单的条件进行查询
		// 将表单转换为参数实体类
		UserInfoBean userInfoB = MyUtils.convertRequest2BeanWithFileUpload(request, UserInfoBean.class);
		// 调用Medol进行业务逻辑
		List<UserInfoBean> lst = EasyFactory.getNewInstance(UserInfoModel.class).queryUserInfoByParams(userInfoB);

		// 把查询结果集转换为json字符串格式，借助于第三方工具 Alibaba 的 fastjson工具 （进行了日期格式转换处理）

		String strJson = JSON.toJSONStringWithDateFormat(lst, "yyyy-MM-dd HH:mm:ss",
				SerializerFeature.WriteDateUseDateFormat);

		//System.out.println("Json::" + strJson);

		// 获取response中的流操作对象PrintWriter
		PrintWriter pw = response.getWriter();
		// 写出内容到浏览器客户端
		pw.write(strJson);
		pw.flush();

	}
}
